package com.biu.zone;

/**
 * Created by zkt on 19/03/27.
 * Description:
 */
public class Tst {

    public void bubbleSort(int[] array) {

        //作用：如果发现已经是有序,就不再遍历排序
        boolean flag = true;

        for (int i = 0; i < array.length - 1 && flag; i++) {
            flag = false;

            for (int j = 0; j < array.length - 1 - i; j++) {
                if (array[j] > array[j + 1]) {
                    int temp = array[j];
                    array[j] = array[j + 1];
                    array[j + 1] = temp;

                    flag = true;
                }
            }
        }

        for (int i = 0; i < array.length; i++) {
            System.out.println(array[i]);
        }
    }

}
